package me.wsj.fengyun.utils;

import android.app.Application;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.WindowManager;

/**
 * Created by cywu4 on 2018/8/8.
 */

public class ApplicationUtils {


    private static Application APPLICATION;

    private static float mScreenWidth = 0;

    private static float mScreenHeight = 0;

    /**
     * 初始化
     */
    public static void init(Application application) {
        APPLICATION = application;
    }

    /**
     * 获取applicationxs
     */
    public static Application getApplication() {
        return APPLICATION;
    }

    /**
     * 获取applicationxs
     */
    public static Context getContext() {
        return APPLICATION;
    }



    /**
     * 获取屏幕宽度
     *
     * @return
     */
    public static float getScreenWidth() {
        if (mScreenWidth <= 0) {
            initScreenSize();
        }
        return mScreenWidth;
    }


    /**
     * 获取屏幕高度
     *
     * @return
     */
    public static float getScreenHeight() {
        if (mScreenHeight <= 0) {
            initScreenSize();
        }
        return mScreenHeight;
    }


    /**
     * 获取屏幕大小 屏幕宽度（像素） 屏幕高度（像素）
     */
    private static void initScreenSize() {
        WindowManager wm = (WindowManager) getApplication().getSystemService(Context.WINDOW_SERVICE);
        DisplayMetrics dm = new DisplayMetrics();
        wm.getDefaultDisplay().getMetrics(dm);
        mScreenWidth = dm.widthPixels;
        mScreenHeight = dm.heightPixels;
    }

}
